package com.cloud.rou.im.client;

import java.util.concurrent.*;

/**
 * <p></p>
 *
 * @author GaoShuangWen
 */
public class A {



    public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {

        FutureTask<String> task = new FutureTask<>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                Thread.sleep(1000L);
                return "qqq";
            }
        });
        new Thread(task).start();
        boolean done = task.isDone();
        long l1 = System.currentTimeMillis();
        String s = task.get(1,TimeUnit.SECONDS);//这个方法会阻塞，直到任务完成时会返回
        boolean done1 = task.isDone();
        long l2 = System.currentTimeMillis();
        System.out.println("任务返回结果 = "+done+"   "+done1+"    time = "+(l2-l1)+"   "+s);
    }
}
